﻿// -----------------------------------------------------------------------
// <copyright file="CreateStockHistoryChart.cs" company="">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace ClearLines.Stocks.UserInterface
{
   using System;
   using System.Collections.Generic;
   using System.Linq;
   using System.Text;
   using Domain;
   using Microsoft.Office.Interop.Excel;
   using Utilities;

   /// <summary>
   /// TODO: Update summary.
   /// </summary>
   public class StockHistoryChart
   {
      public static void Write(StockHistory history, Chart chart)
      {
         var dataPoints = history.History.OrderBy(it => it.Day);
         var values = dataPoints.Select(it => (object)it.Close).ToArray();
         var xValues = dataPoints.Select(it => (object)it.Day).ToArray();

         var close = new SeriesData(history.Symbol, xValues, values);

         ChartWriter.CreateLineChart(chart, close);

         var averages = new List<int>() { 10, 50, 100 };
         foreach (var average in averages)
         {
            var movingAverageValues = dataPoints
               .Select(it => (object)MovingAverage.Compute(history, it.Day, average))
               .ToArray();

            var title = string.Format("MA {0} days", average);
            var movingAverageData = new SeriesData(title, xValues, movingAverageValues);
            ChartWriter.AppendSeries(chart, movingAverageData);
         }
      }
   }
}
